package xyz.wadewhy.basicstest.designPatterns.FactoryModel;

/**
 * @ClassName BehaviorFactory
 * @Description 行为抽象工厂
 * @Author zhongzihao
 * @Date 2021/12/18 11:16 上午
 * @Version 1.0
 **/
abstract class BehaviorFactory {
    /**
     * 模拟动物行为run
     */
    void run() {
        AnimalBehaviorInterface animalBehavior = getAnimalBehavior();
        animalBehavior.run();
    }

    /**
     * 获得动物行为接口
     *
     * @return
     */
    abstract AnimalBehaviorInterface getAnimalBehavior();
}

/**
 * 快的动物，new TigerBehavior
 */
class FastAnimal extends BehaviorFactory {

    @Override
    AnimalBehaviorInterface getAnimalBehavior() {
        return new FastBehavior();
    }
}

/**
 * 慢的动物，new TortoiseBehavior
 */
class SlowAnimal extends BehaviorFactory {

    @Override
    AnimalBehaviorInterface getAnimalBehavior() {
        return new SlowBehavior();
    }
}